package com.mofang.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.mofang.R;
import com.mofang.utils.ListHeightUtils;
import com.pactera.framework.model.MapEntity;

public class InteractiveKnowledgeAdapter extends BaseAdapter {

	private ListView new_house_list;
	private LayoutInflater mInflater;
	Context context;
	ArrayList<MapEntity>  list;

	public InteractiveKnowledgeAdapter(Context context,ArrayList<MapEntity> list) {
		// TODO Auto-generated constructor stub
		this.mInflater = LayoutInflater.from(context);
		this.context = context;
		if(list!=null){
			this.list=list;
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder myHolder;
		if (convertView == null) {
			myHolder = new Holder();
			convertView = mInflater.inflate(
					R.layout.activity_knowledge_interactive_list_item, null);
			myHolder.news_title=(TextView) convertView.findViewById(R.id.news_list_item_newstitle_text);
			myHolder.news_content=(TextView) convertView.findViewById(R.id.news_list_item_newsdetails_text);
			convertView.setTag(myHolder);
		} else {
			myHolder = (Holder) convertView.getTag();
		}
		 myHolder.news_title.setText("标题"+position);
		 myHolder.news_content.setText("内容"+position+">>>>>>.........................");
		 //myHolder.news_time.setText("2014-8-8 12:00");
		 //myHolder.attachment.setImageResource((Integer)(list.get(position).get("attachment")));
		return convertView;
	}

	class Holder {
		//ImageView attachment;
		TextView news_title;
		TextView news_content;
		//TextView news_time;
	}

//	private void setView(LinearLayout parentView) {
//		parentView.removeAllViews();
//		for (int i = 0; i < 10; i++) {
//			View view = mInflater.inflate(
//					R.layout.activity_main_source_list_item, null);
//			parentView.addView(view);
//		}
//	}

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
		ListHeightUtils.setListViewHeightBasedOnChildren(new_house_list);
	}
}
